import { router } from '@/router'
import { RouteRecordRaw } from 'vue-router'
import { useUserStore } from '@/store'

export default () => {
  const asyncAddRoutes = (asyncRoutes: RouteRecordRaw[]) => {
    asyncRoutes.forEach((item: RouteRecordRaw) => {
      router.addRoute(item)
    })
  }

  const removeRoleRoutes = () => {
    const mainStore = useUserStore()
    mainStore.pcRoutes.forEach((item) => {
      router.removeRoute(item.name as string)
    })
  }

  return {
    asyncAddRoutes,
    removeRoleRoutes,
  }
}
